package ensemble.samples.custom.sqlformat.javafx;

import ensemble.samples.custom.sqlformat.javafx.util.AppContext;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

/**
 * @author duanxq
 * @date 2021/6/28
 */
public class MainApp extends Application {

    private BorderPane rootLayout;

    @Override
    public void start(Stage stage) throws Exception {

        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/root.fxml"));
        BorderPane rootLayout = fxmlLoader.load();
        this.rootLayout = rootLayout;
        AppContext.setRootLayout(rootLayout);
        AppContext.setStage(stage);

        stage.setTitle("app");
        stage.getIcons().add(new Image(getClass().getResource("/image/dog.png").toString()));
        stage.setScene(new Scene(rootLayout));
        stage.show();

        showTextSimple();
    }

    private void showTextSimple() throws java.io.IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/textSimple.fxml"));
        this.rootLayout.setCenter(fxmlLoader.load());
    }

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void stop() throws Exception {
        super.stop();
        AppContext.getExecutorService().shutdown();
    }
}
